package com.chenchen.code.guava.eventbus;

import com.chenchen.code.guava.eventbus.listeners.ExceptionListener;
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.SubscriberExceptionContext;
import com.google.common.eventbus.SubscriberExceptionHandler;

/**
* @Description:
* @author chenchen
* @date 2019/5/13 14:53
*/
public class ExceptionEventBusExample
{
    public static void main(String[] args)
    {
        EventBus eventBus = new EventBus(new ExceptionHandler());
        eventBus.register(new ExceptionListener());

        eventBus.post("exception post");
    }


    static class ExceptionHandler implements SubscriberExceptionHandler
    {
        @Override
        public void handleException(Throwable exception, SubscriberExceptionContext context)
        {
            System.out.println(context.getEvent());
            System.out.println(context.getEventBus());
            System.out.println(context.getSubscriber());
            System.out.println(context.getSubscriberMethod());
        }
    }

}
